package cn.smbms.controller;

import cn.smbms.pojo.user.User;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@Controller
public class IndexController{

    private Logger logger=Logger.getLogger(IndexController.class);

    /*@Override
    protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        System.out.println("学框架就学Spring MVC");
        return new ModelAndView("index");
    }*/
    @RequestMapping("/index")
    public String index(){
        logger.info("学框架就学Spring MVC");
        return "index";
    }

    @RequestMapping("/index3")
    public String index(String username, Map<String,Object> model){
        logger.info("hello,SpringMVC! username:"+username);
        model.put("username",username); 
        return "index";
    }



    /**
     * 参数传递：View to Controller
     * @param username
     * @return
     */
    @RequestMapping("/welcome")
    public String welcome(@RequestParam(value = "username",required = false)String username){
        logger.info("welcome,"+username);
        return "index";
    }

    /**
     * 参数传递：controller to view -(ModelAndView)
     * @param username
     * @return
     */
    @RequestMapping("/index1")
    public ModelAndView index(String username){
        logger.info("welcome!username:"+username);
        ModelAndView mView=new ModelAndView();
        mView.addObject("username",username);
        mView.setViewName("index");
        return mView;
    }
}
